
<style lang='scss' scoped>
	.container {
		padding-bottom: calc(64px + var(--window-bottom));
	}
	.parse-content>div {
		width: 100%;
	}
	.get-coupon-content {
		.bottom-title {
		line-height: 60upx;
		font-size: 24upx;
		padding: 15upx 0;
		}
		.bottom-content {
			display: flex;
			flex-wrap: wrap;
			padding: 0 35upx;
		}
		.bottom-content-text {
			font-size: 26upx;
			color: #333;
			margin-top: 10upx;
		}
		.bottom-btn {
			height: 90upx;
			line-height: 90upx;
			border-top: 1px #f5f5f5 solid;
		}
	}
	.xyicon-right {
		font-size: $font-base + 2upx;
		color: #888;
	}
	.carousel {
		height: 722upx;
		position:relative;
		swiper{
			height: 100%;
		}
		.image-wrapper{
			width: 100%;
			height: 100%;
		}
		.swiper-item {
			display: flex;
			justify-content: center;
			align-content: center;
			height: 750upx;
			overflow: hidden;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.promote-box {
			position: absolute;
			bottom: 0;
			width: 100%;
			justify-content: space-between;
			background: linear-gradient(45deg,rgba(255,109,81,1) 0%,rgba(241,68,62,1) 100%);
			min-height: 40px;
			.left {
				padding: 5px 10px;
				color: #fff;
				font-size: 12px;
				.price-box{
					display:flex;
					align-items:baseline;
					padding: 0px 0px;
					font-size: 18px;
					color: #ffd;
					.price{
						font-size: 18px;
					}
					.m-price{
						margin:0 8px;
						color: #fff;
						font-size: 12px;
						text-decoration: line-through;
					}
					.coupon-tip{
						align-items: center;
						padding: 4upx 10upx;
						background: $uni-color-primary;
						font-size: $font-sm;
						color: #fff;
						border-radius: 6upx;
						line-height: 1;
						transform: translateY(-4upx);
					}
				}
			}
			.right {
				width: 120px;
				padding: 5px 10px;
				background-color: #FFDB3C;
				.label {
					font-size: 11px;
					color: #F1443E;
				}
				/deep/ .countdown {
					margin-top: 3px;
					.uni-countdown__number {
						height: 16px;
						padding: 0 1px;
						font-size: 11px;
					}
					.uni-countdown__splitor {
						line-height: 16px;
					}
				}
			}
		}
	}

	/* 标题简介 */
	.introduce-section{
		background: #fff;
		padding: 10px 15px;

		.title{
			font-size: 15px;
			color: $font-color-dark;
			height: 25px;
			line-height: 25px;
		}
		.price-box{
			display:flex;
			align-items:baseline;
			height: 32px;
			padding: 5px 0;
			font-size: 13px;
			color:$uni-color-primary;
			.price{
				font-size: $font-lg + 2upx;
			}
			.m-price{
				margin:0 6px;
				color: $font-color-light;
				text-decoration: line-through;
			}
			.coupon-tip{
				align-items: center;
				padding: 4upx 10upx;
				background: $uni-color-primary;
				font-size: $font-sm;
				color: #fff;
				border-radius: 6upx;
				line-height: 1;
				transform: translateY(-4upx);
			}
		}
		.bot-row{
			display:flex;
			align-items:center;
			height: 50upx;
			font-size: $font-sm;
			color: $font-color-light;
			text{
				flex: 1;
			}
		}
	}
	/* 分享 */
	.share-section {
		&:after {
			border: 0px;
			border-radius: 0px;
		}
		border-radius: 0px;
		display:flex;
		align-items:center;
		color: $font-color-base;
		background: linear-gradient(left, #fdf5f6, #fbebf6);
		padding: 12upx 30upx;
		.share-icon{
			display:flex;
			align-items:center;
			width: 70upx;
			height: 30upx;
			line-height: 1;
			border: 1px solid $uni-color-primary;
			border-radius: 4upx;
			position:relative;
			overflow: hidden;
			font-size: 22upx;
			color: $uni-color-primary;
			&:after{
				content: '';
				width: 50upx;
				height: 50upx;
				border-radius: 50%;
				left: -20upx;
				top: -12upx;
				position:absolute;
				background: $uni-color-primary;
			}
		}
		.xyicon-star{
			position:relative;
			z-index: 1;
			font-size: 24upx;
			margin-left: 2upx;
			margin-right: 10upx;
			color: #fff;
			line-height: 1;
		}
		.tit{
			font-size: $font-base;
			margin-left:10upx;
		}
		.xyicon-help{
			padding: 10upx;
			font-size: 30upx;
			line-height: 1;
		}
		.share-btn{
			flex: 1;
			text-align:right;
			font-size: $font-sm;
			color: $uni-color-primary;
		}
		.icon-you{
			font-size: $font-sm;
			margin-left: 4upx;
			color: $uni-color-primary;
		}
	}

	.c-list{
		font-size: $font-sm + 2upx;
		color: $font-color-base;
		background: #fff;
		.c-row{
			display:flex;
			align-items:center;
			padding: 20upx 30upx;
			position:relative;
		}
		.tit{
			width: 140upx;
		}
		.con{
			flex: 1;
			color: $font-color-dark;
			.selected-text{
				margin-right: 10upx;
			}
		}
		.bz-list{
			height: 40upx;
			font-size: $font-sm+2upx;
			color: $font-color-dark;
			text{
				display: inline-block;
				margin-right: 30upx;
			}
		}
		.con-list{
			flex: 1;
			display:flex;
			flex-direction: column;
			color: $font-color-dark;
			line-height: 40upx;
		}
		.red{
			color: $uni-color-primary;
		}
	}

	.item-list {
		.tit {
			width: auto;
		}
	}
	/* 评价 */
	.eva-section{
		display: flex;
		flex-direction: column;
		padding: 20upx 30upx;
		background: #fff;
		margin-top: 16upx;
		.e-header{
			display: flex;
			align-items: center;
			height: 70upx;
			font-size: $font-sm + 2upx;
			color: $font-color-light;
			.tit{
				font-size: $font-base + 2upx;
				color: $font-color-dark;
				margin-right: 4upx;
			}
			.tip{
				flex: 1;
				text-align: right;
			}
			.icon-you{
				margin-left: 10upx;
			}
		}
	}
	.eva-box{
		display: flex;
		padding: 20upx 0;
		.portrait{
			flex-shrink: 0;
			width: 80upx;
			height: 80upx;
			border-radius: 100px;
		}
		.right{
			flex: 1;
			display: flex;
			flex-direction: column;
			font-size: $font-base;
			color: $font-color-base;
			padding-left: 26upx;
			.con{
				font-size: $font-base;
				color: $font-color-dark;
				padding: 20upx 0;
			}
			.bot{
				display: flex;
				justify-content: space-between;
				font-size: $font-sm;
				color:$font-color-light;
			}
		}
	}
	/*  详情 */
	.detail-desc{
		background: #fff;
		margin-top: 16upx;
		.d-header{
			display: flex;
			justify-content: center;
			align-items: center;
			height: 80upx;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			position: relative;

			text{
				padding: 0 20upx;
				background: #fff;
				position: relative;
				z-index: 1;
			}
			&:after{
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translateX(-50%);
				width: 300upx;
				height: 0;
				content: '';
				border-bottom: 1px solid #ccc;
			}
		}
	}

	/* 规格选择弹窗 */
	.attr-content{
		padding: 10upx 30upx;
		box-sizing: border-box;
		.a-t{
			display: flex;
			image{
				width: 170upx;
				height: 170upx;
				flex-shrink: 0;
				margin-top: -40upx;
				border-radius: 8upx;;
			}
			.right{
				display: flex;
				flex-direction: column;
				padding-left: 24upx;
				font-size: $font-sm + 2upx;
				color: $font-color-base;
				line-height: 42upx;
				.price{
					font-size: $font-lg;
					color: $uni-color-primary;
					margin-bottom: 10upx;
				}
				.selected-text{
					margin-right: 10upx;
				}
			}
		}
		.attr-list{
			display: flex;
			flex-direction: column;
			font-size: $font-base + 2upx;
			color: $font-color-base;
			padding-top: 30upx;
			padding-left: 10upx;
		}
		.item-list{
			padding: 20upx 0 0;
			display: flex;
			flex-wrap: wrap;
			text{
				display: flex;
				align-items: center;
				justify-content: center;
				background: #eee;
				margin-right: 20upx;
				margin-bottom: 20upx;
				border-radius: 100upx;
				min-width: 60upx;
				height: 60upx;
				padding: 0 20upx;
				font-size: $font-base;
				color: $font-color-dark;
			}
			.selected{
				background: #fbebee;
				color: $uni-color-primary;
			}
		}
	}

	/*  弹出层 */
	.popup {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		z-index: 99;

		&.show {
			display: block;
			.mask{
				animation: showPopup 0.2s linear both;
			}
			.layer {
				animation: showLayer 0.2s linear both;
			}
		}
		&.hide {
			.mask{
				animation: hidePopup 0.2s linear both;
			}
			.layer {
				animation: hideLayer 0.2s linear both;
			}
		}
		&.none {
			display: none;
		}
		.mask{
			position: fixed;
			top: 0;
			width: 100%;
			height: 100%;
			z-index: 1;
			background-color: rgba(0, 0, 0, 0.4);
		}
		.layer {
			position: fixed;
			z-index: 99;
			bottom: 0;
			width: 100%;
			min-height: 40vh;
			border-radius: 10upx 10upx 0 0;
			background-color: #fff;
			.btn{
				height: 66upx;
				line-height: 66upx;
				border-radius: 100upx;
				background: $uni-color-primary;
				font-size: $font-base + 2upx;
				color: #fff;
				margin: 30upx auto 20upx;
			}
		}
		@keyframes showPopup {
			0% {
				opacity: 0;
			}
			100% {
				opacity: 1;
			}
		}
		@keyframes hidePopup {
			0% {
				opacity: 1;
			}
			100% {
				opacity: 0;
			}
		}
		@keyframes showLayer {
			0% {
				transform: translateY(120%);
			}
			100% {
				transform: translateY(0%);
			}
		}
		@keyframes hideLayer {
			0% {
				transform: translateY(0);
			}
			100% {
				transform: translateY(120%);
			}
		}
	}

	/* 底部操作菜单 */
	.page-bottom {
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
		position:fixed;
		left: 0px;
		right: 0;
		margin-left: auto;
		margin-right: auto;
		bottom: 0;
		z-index: 95;
		display: flex;
		flex-wrap: wrap;
		padding-top: 0px;
		justify-content: space-around;
		align-items: center;
		width: 100%;
		height: calc(55px + env(safe-area-inset-bottom));
		background: rgba(255,255,255,0.95);
		.p-b-btn{
			display:flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-size: $font-sm;
			color: $font-color-base;
			width: 96upx;
			height: 80upx;
			.xyicon{
				font-size: 40upx;
				line-height: 48upx;
				color: $font-color-light;
			}
			&.active, &.active .xyicon{
				color: $uni-color-primary;
			}
			.icon-fenxiang2{
				font-size: 42upx;
				transform: translateY(-2upx);
			}
			.icon-shoucang{
				font-size: 46upx;
			}
		}
		.action-btn-group{
			display: flex;
			height: 76upx;
			border-radius: 100px;
			overflow: hidden;
			background: $uni-color-primary;
			margin-left: 20upx;
			position:relative;
			&:after{
				content: '';
				position:absolute;
				top: 50%;
				right: 50%;
				transform: translateY(-50%);
				height: 28upx;
				width: 0;
				border-right: 1px solid rgba(255,255,255,.5);
			}
			.action-btn{
				display:flex;
				align-items: center;
				justify-content: center;
				width: 180upx;
				height: 100%;
				font-size: $font-base ;
				padding: 0;
				border-radius: 0;
				background: transparent;
			}
			.add-cart-btn {
				border-color: linear-gradient(135deg,rgba(255,204,0,1) 0%,rgba(255,120,0,1) 98%) !important;
				background: linear-gradient(135deg,rgba(255,204,0,1) 0%,rgba(255,120,0,1) 98%) !important;
			}
		}
	}
</style>

<template>
	<view class="container">
		<view class="carousel">
			<swiper indicator-dots indicator-color="#999999" indicator-active-color="#ffffff" circular=true duration="400">
				<swiper-item class="swiper-item" v-for="(item,index) in info.images" :key="index">
					<view class="image-wrapper">
						<xy-image
							:src="item.url"
							class="loaded"
							mode="aspectFill"
						></xy-image>
					</view>
				</swiper-item>
			</swiper>
			<view
				v-if="promoteType == 1" class="promote-box flex"
				v-show="$store.state.app.siteInfo.versionFuncsAll.indexOf('ishop_seckill') >= 0">
				<view class="left">
					<view class="label">
						限时秒杀中
					</view>
					<view class="price-box">
						<text class="price-tip">¥</text>
						<text class="price">{{promoteInfo.curPrice}}</text>
						<text class="m-price">¥{{info.price}}</text>
					</view>
				</view>
				<view class="right">
					<view class="label">
						距离结束还剩
					</view>
					<view class="countdown">
						<uni-countdown class="timer" color="#fff" :show-day="true" background-color="#333" :second="seckillLeftSeconds">
						</uni-countdown>
					</view>
				</view>
			</view>
		</view>

		<view class="introduce-section m-b-sm">
			<text class="title">{{info.title}}</text>
			<view v-if="promoteType == 0" class="price-box" style="justify-content: space-between;">
				<view class="price">
					<text class="price-tip">¥</text>
					<text class="price">{{info.price}}</text>
					<text class="m-price">¥{{info.originalPrice}}</text>
					<text class="coupon-tip" v-show="info.discount < 10">{{info.discount}}折</text>
				</view>
				<view class="share-item">
					<text class="xyicon xyicon-share" @click="share"></text>
				</view>
			</view>
			<view v-if="promoteType == 0" class="bot-row">
				<text>销量: {{info.buyCount}}</text>
				<text>库存: {{info.totalStock}}</text>
				<text>浏览量: {{info.viewCount}}</text>
			</view>
		</view>

		<!-- 分享 -->
		<button class="share-section m-b-sm" @click="share"
			v-show="$store.state.app.siteInfo.versionFuncsAll.indexOf('ishop_resale') >= 0">
			<view class="share-icon">
				<text class="xyicon xyicon-star"></text> 销
			</view>
			<text class="tit">该商品分享可获得佣金</text>
			<text class="xyicon xyicon-help"></text>
			<view class="share-btn">
				立即分销
				<text class="xyicon icon-right"></text>
			</view>
		</button>

		<view class="c-list">
			<view class="c-row b-b" @click="toggleSpec">
				<text class="tit">购买类型</text>
				<view class="con">
					<text class="selected-text" v-for="(sItem, sIndex) in specSelected" :key="sIndex">
						{{sItem}}
					</text>
				</view>
				<text class="xyicon xyicon-right"></text>
			</view>
			<!-- 规格-模态层弹窗 -->
			<view
				class="popup spec"
				:class="specClass"
				@touchmove.stop.prevent="stopPrevent"
				@click="toggleSpec">
				<!-- 遮罩层 -->
				<view class="mask"></view>
				<view class="layer attr-content safe-bottom" @click.stop="stopPrevent">
					<view class="a-t">
						<xy-image :src="info.cover"></xy-image>
						<view class="right">
							<text class="price">¥{{specSelectedIndex !== '' ? info.skuList[specSelectedIndex].price : '--'}}</text>
							<text class="stock">库存：{{specSelectedIndex !== '' ? info.skuList[specSelectedIndex].stock : 0}}件</text>
							<view class="selected">
								已选：
								<text class="selected-text" v-for="(sItem, sIndex) in specSelected" :key="sIndex">
									{{sItem}}
								</text>
							</view>
						</view>
					</view>
					<view v-for="(item,index) in info.skuSpec" :key="index" class="attr-list">
						<text>{{item.title}}</text>
						<view class="item-list">
							<text
								v-for="(childItem, childIndex) in item.spec"
								:key="childIndex" class="tit"
								:class="{selected: childItem.selected}"
								@click="selectSpec(index, childIndex)">
								{{childItem.title}}
							</text>
						</view>
					</view>
					<button class="btn" @click="toggleSpec">完成</button>
				</view>
			</view>
			<view class="c-row b-b" @click="popupGetCoupon" v-show="$store.state.app.siteInfo.versionFuncsAll.indexOf('coupon') >= 0">
				<text class="tit">优惠券</text>
				<text class="con t-r red">领取优惠券</text>
				<text class="xyicon xyicon-right"></text>
			</view>
			<uni-popup ref="popupCoupon" :show="coupon.getCouponShow" type="bottom" @hidePopup="popupGetCoupon">
				<view class="get-coupon-content bg-white safe-bottom" style="text-align: center;">
					<view class="bottom-title">领券</view>
					<view v-show="coupon.loadingGetCoupon">
						加载中...
					</view>
					<view class="bottom-content">
						<view class="coupon-list" style="width: 750rpx;">
							<xy-coupon
								v-for="(item) in coupon.couponList"
								:key="item.id"
								v-bind:item="item"
								@action="getCoupon"
								types="carts"
								theme="#ff6c00"
								color="#ffffff"
								solid="#ff6c00">
							</xy-coupon>
						</view>
					</view>
					<view class="bottom-btn" @click="popupGetCoupon">取消</view>
				</view>
			</uni-popup>
			<view class="c-row b-b" style="display: none;">
				<text class="tit">促销活动</text>
				<view class="con-list">
					<text>新人首单送20元无门槛代金券</text>
					<text>订单满50减10</text>
					<text>订单满100减30</text>
					<text>单笔购买满两件免邮费</text>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">服务</text>
				<view class="bz-list con">
					<text :key="item.value" v-for="item in info.serviceList">{{item.title}} ·</text>
				</view>
			</view>
		</view>

		<!-- 评价 -->
		<view class="eva-section" @click="comment(info.id)">
			<view class="e-header">
				<text class="tit">评价</text>
				<text>({{info.commentCount}})</text>
				<text class="tip">好评率 {{info.favorableRate}}%</text>
				<text class="xyicon icon-you"></text>
			</view>
			<view class="eva-box" :key="item.id" v-for="item in info.commentList">
				<xy-image class="portrait" :src="item.userInfo.avatar" mode="aspectFill"></xy-image>
				<view class="right">
					<text class="name">{{item.userInfo.nickname}}</text>
					<text class="con">{{item.content}}</text>
					<view class="bot">
						<text class="attr">购买类型：{{item.skuSpec}}</text>
						<text class="time">{{item.createTime | formatTime}}</text>
					</view>
				</view>
			</view>
		</view>

		<view class="detail-desc">
			<view class="d-header">
				<text>图文详情</text>
			</view>
			<view class="content">
				<u-parse className="parse-content" :content="info.content" />
			</view>
		</view>

		<!-- 底部操作菜单 -->
		<view class="page-bottom safe-bottom">
			<navigator url="/pages/home" open-type="switchTab" class="p-b-btn">
				<text class="xyicon xyicon-home"></text>
				<text>首页</text>
			</navigator>
			<navigator url="/pages/ishop/cart/my" open-type="switchTab" class="p-b-btn">
				<text class="xyicon xyicon-cart"></text>
				<text>购物车</text>
			</navigator>
			<view class="p-b-btn" :class="{active: favorite}" @click="toFavorite">
				<text class="xyicon xyicon-heart"></text>
				<text>收藏</text>
			</view>
			<view class="action-btn-group">
				<button type="primary" :disabled="specSelectedIndex === '' ? true: false" v-if="promoteType == 0" class=" action-btn no-border add-cart-btn" @click="addCart">加入购物车</button>
				<button type="primary" :disabled="specSelectedIndex === '' ? true: false" v-if="promoteType > 0" class="action-btn no-border add-cart-btn" @click="goShopInfo">直接购买</button>
				<button type="primary" :disabled="specSelectedIndex === '' ? true: false" class=" action-btn no-border buy-now-btn" @click="buy">立即购买</button>
			</view>
		</view>

		<!-- 分享 -->
		<xy-share ref="share" :contentHeight="580"></xy-share>
		<xy-poster
			ref="poster"
            :postersData="postersData"
            @success="onSuccessCreatePosters"
            @error="onPostersError">
        </xy-poster>
	</view>
</template>

<script>
	import uParse from '@/components/gaoyia-parse/parse.vue';
	export default{
		components: {
			uParse
		},
		data() {
			return {
				id: 0,
				promoteType: 0,
				promoteId: 0,
				promoteInfo: {
					curPrice: 0.00,
				},
				seckillLeftSeconds: 0,
				info: {
					content: '加载中...',
					skuList: [],
				},
				specClass: 'none',
				specSelected:[],
				specSelectedIndex: '',
				coupon: {
					getCouponShow: false,
					loadingGetCoupon: false,
					couponList: [],
				},
				favorite: false,
				postersData: {},
				posterImg: {},
				orderInfo: {}
			};
		},
		onShareAppMessage(res) {
			if (res.from === 'button') {// 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: this.info.title,
				imageUrl: this.posterImg.path,
				path: '/pages/ishop/item/info?id=' + this.info.id
			}
		},
		async onLoad(options){
			uni.showLoading({
				title: '加载中...'
			})
			//接收传值,id里面放的是标题，因为测试数据并没写id
			this.id = options.id;
			if (options.promoteType) {
				this.promoteType = options.promoteType
			}
			if (options.promoteId) {
				this.promoteId = options.promoteId
			}
			if(this.id){
				let res = await this.util.request({
					url: '/v1/ishop/item/info/' + this.id,
					method: 'get'
				});
				if (res.code == 200) {
					res.data.info.content = res.data.info.content.replace(
						/\<img/gi,
						'<img style="max-width:100%;height:auto" '
					);
					this.info = res.data.info;
					//规格 默认选中第一条
					this.info.skuSpec.forEach(item=>{
						console.log(item);
						this.$set(item.spec[0], 'selected', true);
						this.specSelected.push(item.spec[0].title);
					});
					this.specSelectedIndex = 0;
				}
			}
			uni.hideLoading();
			
			// 秒杀
			if (this.promoteType == 1) {
				await this.getSeckillInfo();
				this.seckillLeftSeconds = (new Date((this.promoteInfo.endTime).replace(/\-/g, "/"))).getTime()/1000 - Date.parse(new Date())/1000;
			}

			if (this.$store.state.user.token) {
				// 获取收藏状态
				let res1 = await this.util.request({
					url: '/v1/ishop/collect/my/0',
					method: 'get',
					data: {
						dataId: this.info.id
					}
				});
				if (res1.code == 200) {
					if (res1.data.dataList.length > 0) {
						this.favorite = true;
					}
				}
				
				// 提交访问历史到后台
				let resHistory = await this.util.request({
					url: '/v1/ishop/history/add',
					method: 'post',
					data: {
						dataType: 0,
						storeId: this.info.storeId,
						dataValue: this.info.id
					}
				});
			}
		},
		watch:{
			'coupon.getCouponShow'(newVal) {
				if (newVal == true) {
					this.$refs.popupCoupon.open();
				} else {
					this.$refs.popupCoupon.close();
				}
			}, 
		},
		methods:{
			goShopInfo(){
				uni.navigateTo({
					url: '/pages/ishop/item/info?id=' + this.info.id
				})
			},
			async getSeckillInfo(){
				let res = await this.util.request({
					url: '/v1/ishop_seckill/seckill/info/' + this.promoteId,
					method: 'get'
				});
				if (res.code == 200) {
					this.promoteInfo = res.data.info;
				}
			},
			comment(itemId){
				uni.navigateTo({
					url: '/pages/ishop/comment/lists?itemId=' + itemId
				});
			},
			// 领取优惠券
			async getCoupon(id) {
				let res = await this.util.request({
					url: '/v1/coupon/tpl/get',
					method: 'post',
					data: {
						id: id
					}
				});
				if (res.code == 200) {
					this.util.showToast({
						title: res.msg,
						icon: 'success',
						duration: 1000
					});
				} else {
					this.util.showToast({
						title: res.msg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			// 隐藏领取优惠券
			async popupGetCoupon() {
				this.coupon.getCouponShow = !this.coupon.getCouponShow;
				if (this.coupon.couponList.length == 0) {
					this.coupon.loadingGetCoupon = true;
					let res = await this.util.request({
						url: '/v1/coupon/tpl/lists',
						method: 'get',
						data: {
							groupName: 'store', // 表示店铺券
							eid: this.info.storeId // 表示店铺ID
						}
					});
					if (res.code == 200) {
						this.coupon.couponList = res.data.dataList;
					} else {
						this.util.showToast({
							title: res.msg,
							icon: 'error',
							duration: 2000
						});
					}
					this.coupon.loadingGetCoupon = false;
				}
			},
			// 加入购物车
			async addCart() {
				if (this.specSelectedIndex === '') {
					this.toggleSpec();
				}
				let res = await this.util.request({
					url: '/v1/ishop/cart/add',
					method: 'post',
					data: {
						skuId: this.info.skuList[this.specSelectedIndex].id,
						promoteId: this.promoteId,
						promoteType: this.promoteType
					}
				});
				if (res.code == 200) {
					this.util.showToast({
						title: res.msg,
						icon: 'loading',
						duration: 1000
					});
				} else {
					this.util.showToast({
						title: res.msg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			//规格弹窗开关
			toggleSpec() {
				if(this.specClass === 'show'){
					this.specClass = 'hide';
					setTimeout(() => {
						this.specClass = 'none';
					}, 250);
				} else if(this.specClass === 'none'){
					this.specClass = 'show';
				}
			},
			//选择规格
			selectSpec(index, childIndex){
				let list = this.info.skuSpec[index].spec;
				list.forEach(item=>{
					this.$set(item, 'selected', false);
				})
				this.info.skuSpec[index].spec[childIndex].selected = true;
				/**
				 * 存储已选择
				 * 修复选择规格存储错误
				 * 将这几行代码替换即可
				 * 选择的规格存放在specSelected中
				 */
				this.specSelected[index] = this.info.skuSpec[index].spec[childIndex].title;

				let skuExist = false;
				for (let i = 0; i < this.info.skuList.length; i++) {
					console.log(this.info.skuList);
					console.log(this.info.skuList[i].spec + '---' + this.specSelected.join(','))
					if (this.info.skuList[i].spec == this.specSelected.join(',')) {
						console.log('存在');
						this.specSelectedIndex = i;
						skuExist = true;
						break;
					} else {
						console.log('不存在');
					}
				}
				if (skuExist == false) {
					this.specSelectedIndex = '';
				}
			},
			//分享
			share(){
				this.util.showToast({
					title: '海报生成中...',
					icon: 'loading',
					duration: 10000
				});
				this.initPostersConfig();
				this.$refs.poster.createPosters(this.postersData);
			},
			realShare(){
				this.$refs.share.togglePopup({
					systemShare: true, // 是否在APP上启用系统分享避免需要申请各种appid
					type: 2, // 0图文1文字2图片
					title: this.info.title,
					summary: this.info.title,
					imageUrl: this.posterImg.path,
					imageWidth: '660rpx',
					imageHeight: '850rpx',
					href: this.util.baseDomain() + '/m/pages/ishop/item/info?id=' + this.info.id,
					success: function (res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function (err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			initPostersConfig() {
				let cover = this.util.imageCache(this.info.cover);
				const config = {
					clear: true,
					width: 660,
					height: 850,
					background: '#ffffff',
					views: [
						{
							type: 'image',
							width: 660,
							height: 660,
							top: 0,
							left: 0,
							url: cover
						},
						{
							type: 'text',
							width: 400,
							height: 50,
							left: 20,
							top: 680,
							fontSize: 30,
							lineHeight: 40,
							bolder: true,
							breakWord: true,
							content: '        ' + this.info.title,
							MaxLineNumber: 2
						},
						{
							type: 'rect',
							width: 70,
							height: 34,
							left: 20,
							top: 684,
							background: '#ff4201',
							radius: 8
						},
						{
							type: 'text',
							width: 400,
							height: 50,
							left: 20,
							top: 690,
							fontSize: 24,
							lineHeight: 40,
							bolder: true,
							breakWord: true,
							content: ' 活动',
							color: '#ffffff',
							MaxLineNumber: 2
						},
						{
							type: 'text',
							width: 400,
							left: 20,
							top: 770,
							fontSize: 54,
							bolder: true,
							breakWord: true,
							content: '￥' + this.info.price,
							color: '#F40',
							MaxLineNumber: 2
						},
						{
							type: 'image',
							width: 140,
							height: 140,
							top: 680,
							left: 500,
							// 二维码图片路径，测试的时候填上
							value: (this.util.baseUrl()
								+ 'pages/ishop/item/info?id='
								+ this.info.id),
							url: this.$store.state.app.siteInfo.qrcodeApi + encodeURI(this.util.baseUrl())
						},
					]
				};
				this.postersData = config;
			},
			onSuccessCreatePosters(res) {
				console.log(res);
				uni.hideToast();
				this.posterImg = res;
				this.realShare();
			},
			onPostersError(res) {
				console.log(res)
			},
			//收藏
			async toFavorite(){
				let isCancel = this.favorite ? 1 : 0;
				let res = await this.util.request({
					url: '/v1/ishop/collect/add',
					method: 'post',
					data: {
						dataId: this.info.id,
						isCancel: isCancel
					}
				});
				if (res.code == 200) {
					this.favorite = !this.favorite;
					this.util.showToast({
						title: res.msg,
						icon: 'loading',
						duration: 1000
					});
				} else {
					this.util.showToast({
						title: res.msg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			buy(){
				if (this.util.isLogin()) {
					let that = this;
					this.orderInfo[that.info.storeId] = {
						'skuList': [
							{
								itemId: this.info.id,
								skuId: this.info.skuList[this.specSelectedIndex].id,
								amount: 1,
								promoteId: this.promoteId,
								promoteType: this.promoteType
							}
						]
					};
					console.log(this.orderInfo);
					uni.navigateTo({
						url: `/pages/ishop/order/create?data=${JSON.stringify({
							orderInfo: this.orderInfo
						})}`
					});
				}
			},
			stopPrevent(){}
		}
	}
</script>

